package com.yanqu.road.server.cmd.tradewar.cross;

import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.pb.cross.tradewar.CrossTradeWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.TradeWarModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_CROSS_TRADE_WAR_PUBLISH_WANTED, desc = "跨服商战发布通缉")
public class CrossTradeWarPublishWantedCmd extends AbstractCommand {
	private int activityId;
	private long wantedUserId;
	private long wantedServerId;
	private int useItemId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CrossTradeWarProto.CrossTradeWarPublishWantedReqMsg reqMsg = CrossTradeWarProto.CrossTradeWarPublishWantedReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		wantedUserId = reqMsg.getWantedUserId();
		wantedServerId = reqMsg.getWantedServerId();
		useItemId = reqMsg.getUseItemId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		if(0 == useItemId){
			useItemId = GameConfig.TRADE_WAR_WANTED_ITEM_ID;
		}
		ret = player.getModule(TradeWarModule.class).publishCrossTradeWarWanted(activityId, wantedUserId, wantedServerId, useItemId);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(0 != ret) {
			CrossTradeWarProto.CrossTradeWarPublishWantedRespMsg.Builder respMsg = CrossTradeWarProto.CrossTradeWarPublishWantedRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_CROSS_TRADE_WAR_PUBLISH_WANTED, respMsg);
		}
	}
}
